<!-- 个人信息 -->
<template>
	<view class="container p30">
		<form @submit="submitTap">
			<view class="formItem">
				<view class="label mast">姓名</view>
				<input type="text" :value="userDetail.name" name="name" placeholder="请输入姓名" placeholder-class="c6e"/>
			</view>
			<view class="formItem">
				<view class="label mast">省市区</view>
				<picker mode="region" @change="pickerAdd">
					<view class="">{{address?address:"选择省市区"}}</view>
				</picker>
			</view>
			<view class="formItem">
				<view class="label">性别</view>
				<radio-group name="gender">
					<label class="radio">
						<radio value="M" :checked="userDetail.gender == 'M'" /><text>男</text>
					</label>
					<label class="radio">
						<radio value="F" :checked="userDetail.gender == 'F'" /><text>女</text>
					</label>
				</radio-group>
			</view>
			<view class="formItem" >
				<view class="label">出生年月</view>
				<picker mode="date" @change="pickerDate"  :value="date" name='birth'>
					<view class="picker">{{date?date:'请选择日期'}}</view>
				</picker>
			</view>
			<view class="formItem">
				<view class="label">电话</view>
				<input type="number" :value="userDetail.tel" name="tel" placeholder="请输入电话" placeholder-class="c6e" />
			</view>
			<view class="formItem">
				<view class="label">惯用手</view>
				<radio-group  name="preferred_hand_side">
					<label class="radio">
						<radio value="L"  :checked="userDetail.preferred_hand_side == 'L'" /><text>右手</text>
					</label>
					<label class="radio">
						<radio value="R" :checked="userDetail.preferred_hand_side == 'R'"/><text>左手</text>
					</label>
				</radio-group>
			</view>
<!-- 			<view class="formItem">
				<view class="label">家族史</view>
				<radio-group name="family_history" >
					<label class="radio">
						<radio value="无" :checked="userDetail.family_history == '无'" /><text>无</text>
					</label>
					<label class="radio">
						<radio value="有" :checked="userDetail.family_history == '有'"/><text>有</text>
					</label>
				</radio-group>
			</view> -->
			<view class="formItem" >
				<view class="label">当前诊断</view>
				<picker :range="history" @change="pickerHistory" :value="history[hisIndex]"  name="diagnose">
					<view class="">{{history[hisIndex]?history[hisIndex]:'请选择当前诊断'}}</view>
				</picker>
			</view>
			<view class="formItem">
				<view class="label">教育程度</view>
				<picker :range="degree" :value="degIndex" @change="pickerDegree"  name="education">
					<view class="">{{degree[degIndex]?degree[degIndex]:'请选择教育程度'}}</view>
				</picker>
			</view>
			
			<button class="btn" form-type="submit" type="default">提交</button>
		</form>
	</view>
</template>

<script>
	export default {
		name:"",
		data() {
			return {
				date:'',
				history:['从未就诊','就诊过，但诊断不详','帕金森病','帕金森高危人群','帕金森综合征','其它'],
				hisIndex:-1,
				degree:['小学','初中','高中','大学','其他'],
				degIndex:-1,
				userDetail:{},
				address:""
			}
		},
		onShow() {
			this.getUserDetail()
		},
		methods: {
			pickerAdd(e){
				console.log(e,'4343');
				this.address = e.detail.value[0]+	e.detail.value[1]+e.detail.value[2]
			},
			
			/**
			 * 更改用户基本信息
			 * @param {Object} e 表单数据
			 */
			submitTap(e){
				
				let _this = this, form = e.detail.value;
				console.log(form);
				if(!form.name){
					uni.showToast({
						title:"姓名为空！",
						icon:"none"
					})
					return false
				}
				if(_this.address == ''){
					uni.showToast({
						title:"省市区为空！",
						icon:"none"
					})
					return false
				}
				// if(!form.gender){
				// 	wx.showToast({
				// 		title:"性别为空！",
				// 		icon:"none"
				// 	})
				// 	return false
				// }
				// if(!form.birth){
				// 	wx.showToast({
				// 		title:"出生年月为空！",
				// 		icon:"none"
				// 	})
				// 	return false
				// }
				// if(!form.tel){
				// 	wx.showToast({
				// 		title:"电话为空！",
				// 		icon:"none"
				// 	})
				// 	return false
				// }
				// if( !/^1[3-9]\d{9}$/.test(form.tel)  ){
				// 	wx.showToast({
				// 		title:"电话规格不正确！",
				// 		icon:"none"
				// 	})
				// 	return false
				// }
				// if(!form.preferred_hand_side){
				// 	wx.showToast({
				// 		title:"惯用手为空！",
				// 		icon:"none"
				// 	})
				// 	return false
				// }
				// if(!form.family_history){
				// 	wx.showToast({
				// 		title:"家族史为空！",
				// 		icon:"none"
				// 	})
				// 	return false
				// }
				// if(!form.diagnose){
				// 	wx.showToast({
				// 		title:"当前诊断为空！",
				// 		icon:"none"
				// 	})
				// 	return false
				// }
				// if(!form.education){
				// 	wx.showToast({
				// 		title:"教育程度为空！",
				// 		icon:"none"
				// 	})
				// 	return false
				// }
				form.address = _this.address;
				_this.$utils.request({
					url:'/patient/user_info/',
					method:"PUT",
					data:{
						basic_info:form,
					}
				}).then(res=>{
					wx.showToast({
						title:"更改成功！"
					})
					setTimeout(()=>{
						_this.$routeJump.back()
					},2000)
				})
				
			},
			/**
			 * 请求用户信息
			 */
			getUserDetail(){
				let _this = this;
				 _this.$utils.request({
					 url:"/patient/user_info/",
				 }).then(res=>{
					 _this.userDetail = res.data.basic_info;
					 _this.degIndex = res.data.basic_info.education;
					 _this.address = res.data.basic_info.address;
					 _this.date = res.data.basic_info.birth != '1900-01-01'?res.data.basic_info.birth:'';
					 _this.hisIndex = _this.history.indexOf(res.data.basic_info.diagnose)
				 })
			},
			
			
			
			/**  时间选择
			 * @param {Object} e picker返回参数
			 */
			pickerDate(e){
				this.date = e.detail.value;
			},
			/** 家族史选择
			 * @param {Object} e picker返回参数
			 */
			pickerHistory(e){
				this.hisIndex = e.detail.value;
			},
			/** 教育程度选择
			 * @param {Object} e picker返回参数
			 */
			pickerDegree(e){
				this.degIndex = e.detail.value;
			},
		}
	}
	
</script>

<style lang="scss" scoped>
	.formItem{
		width: 100%;
		height: 96rpx;
		line-height: 96rpx;
		border-bottom: 1rpx solid #ddd;
		color: #6e6e6e;
		@include flex(space-between,center)
		.label{
			width:160rpx;
		}
		.mast::after{
			content: "*";
			color: $uni-theme-color;
		}
		input{
			flex: 1;
			height: 96rpx;
			line-height: 96rpx;
			text-align: right;
		}
		.radio{
			display: inline-block;
			width: 140rpx;
		}
	}
	.c6e{
		color: #6e6e6e;
	}
	.btn{
		width: 75%;
		height: 84rpx;
		line-height: 84rpx;
		margin: 0 auto 50rpx;
		border-radius: 50rpx;
		background-color: #ffb526;
		margin-top: 40rpx;
	}
</style>
